package com.jiyi.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiyi.bean.maintenance.DetectCate;
import com.swift.maintenance.R;

import java.util.List;

/**
 * 维保派发 adapter
 * 
 * */
public class DetectAdapter extends BaseAdapter {

	private List<DetectCate> dataList;
	private Context mContext;

	public DetectAdapter(Context context, List<DetectCate> data) {
		this.mContext = context;
		this.dataList = data;
	}

	@Override
	public int getCount() {
		if (dataList != null) {
			return dataList.size();
		} else {
			return 0;
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {

			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_detect_content, parent, false);

			viewHolder.rlRoot = (RelativeLayout) convertView.findViewById(R.id.rlRoot);
			viewHolder.tvItemContent = (TextView) convertView.findViewById(R.id.tvItemContent);
			viewHolder.ivStatus = (ImageView) convertView.findViewById(R.id.ivStatus);
			viewHolder.ivErrorTip = (ImageView) convertView.findViewById(R.id.ivErrorTip);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		DetectCate datectCate = dataList.get(position);
		
		viewHolder.tvItemContent.setText(datectCate.getName());
		if (datectCate.getStatus() == 2) {
			//已经完成
			viewHolder.tvItemContent.setTextColor(Color.parseColor("#FFFFFF"));
			viewHolder.rlRoot.setBackgroundResource(R.drawable.round_detect_item_check);
			viewHolder.ivStatus.setVisibility(View.VISIBLE);
			if (datectCate.getFault_num()>0) {
				viewHolder.ivErrorTip.setVisibility(View.VISIBLE);
			}
			else {
				viewHolder.ivErrorTip.setVisibility(View.GONE);
			}
		}
		else {
			//未完成
			viewHolder.tvItemContent.setTextColor(Color.parseColor("#3190F1"));
			viewHolder.rlRoot.setBackgroundResource(R.drawable.round_detect_item_uncheck);
			viewHolder.ivStatus.setVisibility(View.GONE);
			viewHolder.ivErrorTip.setVisibility(View.GONE);
		}
				
		return convertView;
	}

	class ViewHolder {

		private RelativeLayout rlRoot;
		private TextView tvItemContent;
		private ImageView ivStatus;
		private ImageView ivErrorTip;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

}
